using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Threading;

namespace zCO
{
    public static class BackUpDB
    {
        public static void Create()
        {
            try
            {
                Thread th1 = new Thread(new ThreadStart(CreateBackUP));
                th1.Start();
            }
            catch
            {


            }

        }
        private static void CreateBackUP()
        {

            if (!Directory.Exists("C:\\backUpDB"))
            {
                Directory.CreateDirectory("C:\\backUpDB");
            }
            string uncompressed = "C:\\backUpDB" + "\\db" + DateTime.Now.ToString("dd-MM-yyyy") + ".mdb";


            string backup = "C:\\backUpDB" + "\\db" + DateTime.Now.ToString("dd-MM-yyyy") + ".mdb" + ".gz";
            

            if (!File.Exists(backup))
            {
                File.Copy(System.AppDomain.CurrentDomain.BaseDirectory + "bd.mdb", uncompressed, true);

                GZip.Compress(uncompressed, backup);
                File.Delete(uncompressed);
                if (DateTime.Today.Day == 9 || DateTime.Today.Day == 20 || DateTime.Today.Day == 27)
                {

                    Mailing.SendMail("Base de Datos de prodentis del " + DateTime.Today.ToShortDateString(), "...", "development@zetasoft.com.ar", "marianomiani@gmail.com", backup);
                }

            }
        }

    }

}